
#include "less_equal_tiling.h"
#include "register/op_def_registry.h"
#include "tiling_common.h"
namespace optiling
{
int64_t get_mem_addtion(ge::DataType dtype)
{
    switch (dtype)
    {
    case ge::DataType::DT_FLOAT:
        return 2;
    case ge::DataType::DT_FLOAT16:
        return 3;
    case ge::DataType::DT_INT8:
        return 9;
    case ge::DataType::DT_INT32:
        return 4;
    }
    return 0;
}

static ge::graphStatus TilingFunc(gert::TilingContext *context)
{
    LessEqualTilingData tiling;
    set_size_by_input(tiling, context, 0);
    CommonTiling<LessEqualTilingData> commonTiling;
    commonTiling.tiling = &tiling;
    commonTiling.context = context;
    commonTiling.data_size = tiling.get_size();
    commonTiling.vector_align_size = 256;
    commonTiling.input_arg_count = 2;
    commonTiling.output_arg_count = 1;
    commonTiling.mem_addition = get_mem_addtion;
    commonTiling.apply();
    tiling_zero_workspace(context);
    tiling_save_to_buffer(tiling, context);
    return ge::GRAPH_SUCCESS;
}
} // namespace optiling

namespace ge
{
static ge::graphStatus InferShape(gert::InferShapeContext *context)
{
    const gert::Shape *x1_shape = context->GetInputShape(0);
    gert::Shape *y_shape = context->GetOutputShape(0);
    *y_shape = *x1_shape;
    return GRAPH_SUCCESS;
}
} // namespace ge

namespace ops
{
class LessEqual : public OpDef
{
  public:
    explicit LessEqual(const char *name) : OpDef(name)
    {
        this->Input("x1")
            .ParamType(REQUIRED)
            .DataType({ge::DT_FLOAT, ge::DT_FLOAT16, ge::DT_INT32, ge::DT_INT8})
            .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND})
            .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND});
        this->Input("x2")
            .ParamType(REQUIRED)
            .DataType({ge::DT_FLOAT, ge::DT_FLOAT16, ge::DT_INT32, ge::DT_INT8})
            .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND})
            .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND});
        this->Output("y")
            .ParamType(REQUIRED)
            .DataType({ge::DT_BOOL, ge::DT_BOOL, ge::DT_BOOL, ge::DT_BOOL})
            .Format({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND})
            .UnknownShapeFormat({ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND, ge::FORMAT_ND});

        this->SetInferShape(ge::InferShape);

        this->AICore().SetTiling(optiling::TilingFunc);

        this->AICore().AddConfig("ascend310b");
    }
};

OP_ADD(LessEqual);
} // namespace ops
